package com.zbkj.front.controller.merchant.monitor;

import com.zbkj.common.model.admin.SystemAdmin;
import com.zbkj.common.model.merchant.Merchant;
import com.zbkj.common.model.monitor.ZfbMonitorOrder;
import com.zbkj.common.result.CommonResult;
import com.zbkj.service.service.MerchantService;
import com.zbkj.service.service.UserService;
import com.zbkj.service.service.monitor.IZfbMonitorOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName: ZfbMonitorOrderController
 * @Description: 监控设备订单
 * @Author: fanbing
 * @Date: 2024/11/2 12:06
 * @Version: V1.0
 **/

@Slf4j
@RestController
@RequestMapping("api/front/merchant/zfbMonitorOrder")
@Api(tags = "商户端-监控设备订单") //配合swagger使用
public class ZfbMonitorOrderController {


    @Autowired
    private IZfbMonitorOrderService zfbMonitorOrderService;
    @Autowired
    private UserService userService;


    @Autowired
    private MerchantService merchantService;

    @ApiOperation(value = "下单")
    @RequestMapping(value = "/placeOrder", method = RequestMethod.POST)
    public CommonResult placeOrder(@RequestBody ZfbMonitorOrder zfbMonitorOrder) {
        SystemAdmin systemAdmin = userService.getSystemAdminByMerchantEmployee();

        Merchant merchant = merchantService.getByIdException(systemAdmin.getMerId());

        zfbMonitorOrder.setMerchantName(merchant.getName());
        zfbMonitorOrder.setMerchantId(systemAdmin.getMerId());
        zfbMonitorOrder.setUserId(systemAdmin.getId());

        return CommonResult.success(zfbMonitorOrderService.createOrder(zfbMonitorOrder));
        // return CommonResult.success(zfbMonitorOrderService.wxUnifiedorder(zfbMonitorOrder));
    }

    @ApiOperation(value = "订单列表")
    @RequestMapping(value = "/getOrderList", method = RequestMethod.GET)
    public CommonResult getOrderList() {
        SystemAdmin systemAdmin = userService.getSystemAdminByMerchantEmployee();
        Merchant merchant = merchantService.getByIdException(systemAdmin.getMerId());
        return CommonResult.success(zfbMonitorOrderService.getOrder(merchant.getId()));
    }
}
